import axios from "axios";
import { ENV_CONFIG } from '../../config/index.js'

// 默认配置
const defaultOptions = {
  baseURL: ENV_CONFIG.baseUrl, // baseURL
  timeout: 10 * 1000, // request timeout
};

export const service = axios.create(defaultOptions);

// 请求拦截器
service.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    console.log(error); // for debug
    return Promise.reject(error);
  }
);

// 响应拦截器
service.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    console.log("err:" + error); // for debug
    const msg = error.message || ErrorMessage.ERROR;
    return Promise.reject(error);
  }
);
